﻿using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using BikeBouncer.BusinessLayer;

namespace BikeBouncer.Site
{
	public partial class MainLayout_master : MasterPage
	{
		#region Properties

		public String H1
		{
			get
			{
				return LitPageH1.Text;
			}
			set
			{
				LitPageH1.Text = value;
			}
		}

		public String ErrorTitle
		{
			get
			{
				return LitErrorTitle.Text;
			}
			set
			{
				LitErrorTitle.Text = value;
			}
		}

		public PlaceHolder Errors
		{
			get
			{
				return PlaceErrors;
			}
		}

		public Ads_ascx FooterAds
		{
			get
			{
				return AdsBottom;
			}
		}

		#endregion

		#region Main methods

		protected void Page_Load(Object sender, EventArgs e)
		{
			if (Page.IsPostBack)
			{
				PlaceErrors.Controls.Clear();
			}

			FlagDE.CssClass = "FlagInactive";
			FlagUK.CssClass = "FlagInactive";
			
			FlagDE.Attributes.Add("onmouseover", "this.className='FlagHover';");
			FlagUK.Attributes.Add("onmouseover", "this.className='FlagHover';");
			
			FlagDE.Attributes.Add("onmouseout", "this.className='FlagInactive';");
			FlagUK.Attributes.Add("onmouseout", "this.className='FlagInactive';");

			String country = SessionManager.CurrentCountry;

			if (country == "DE")
			{
				FlagDE.Attributes.Add("onmouseout", "this.className='FlagActive';");
				FlagDE.CssClass = "FlagActive";
			}
			else if (country == "UK")
			{
				FlagUK.Attributes.Add("onmouseout", "this.className='FlagActive';");
				FlagUK.CssClass = "FlagActive";
			}
		}

		protected void Page_PreRender(Object sender, EventArgs e)
		{
			ImgHeader.ImageUrl = "/Images/Ico/Header" + Path.GetFileNameWithoutExtension(Request.PhysicalPath) + ".png";

			PanError.Visible = Errors.Controls.Count > 0;

			LinkTopMyDetails.Visible = (SessionManager.LoggedUser != null);
			LinkTopLogout.Visible = (SessionManager.LoggedUser != null);
			
			if (SessionManager.LoggedUser != null)
			{
				LblLoggedAs.Text = GetLocalResourceObject("LoggedAs") + " " + SessionManager.LoggedUser.ToString();
			}
			else
			{
				LblLoggedAs.Visible = false;
			}
		}

		#endregion
	}
}